package javax.annotation.processing;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Set;

import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;

import org.junit.Test;

import de.jmda.core.MarkerAnnotationType;
import de.jmda.core.mproc.AbstractJUTProcessors;
import de.jmda.core.mproc.Processor;

public class JUTAbstractProcessor extends AbstractJUTProcessors
{
	@SupportedAnnotationTypes(value = { "de.jmda.core.MarkerAnnotationType" })
	@SupportedSourceVersion(value = SourceVersion.RELEASE_7)
	@MarkerAnnotationType
	private final class PrivateProcessor extends Processor
	{
		int rounds = 0;

		@Override
    public boolean process(
    		Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
    {
			rounds++;
			System.out.println(
					"round: " + rounds + ", processingOver: " + roundEnv.processingOver());
	    return false;
    }

		@Override
		protected Set<Class<? extends Annotation>> getSupposedSupportedAnnotationTypes()
		{
			return asSet(MarkerAnnotationType.class);
		}

		/**
		 * Should not ever be called because
		 * {@link AbstractProcessor#process(Set, RoundEnvironment)} is finally
		 * overridden by {@link #process(Set, RoundEnvironment)} and the latter does
		 * not call this method.
		 *
		 * @see de.jmda.core.mproc.Processor#process()
		 */
		@Override
    protected boolean process()
    {
			System.out.println("empty implementation, should never be called");
	    return false;
    }
	}
	
	private PrivateProcessor processor;
	private List<? extends Processor> processors;
	
	@Override
	protected List<? extends Processor> getProcessors()
	{
		processor = new PrivateProcessor();
		processors = asList(processor);
		return processors;
	}
	
	@Test
	public void test()
	{
		assertEquals("unexpected number of rounds", 2, processor.rounds );
	}
}